﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.Xml;
using System.IO;

namespace BinaryTimesCore
{
    public static class Helper
    {
        //public static object CloneUIElement(object uiElement)
        //{
        //    if (uiElement == null)
        //        return null;

        //    string xaml = XamlWriter.Save(uiElement);
        //    return XamlReader.Load(XmlReader.Create(new StringReader(xaml)));
        //}

        public static string CreateRandomString(int length)
        {
            string result = String.Empty;

            for (int i = 0; i < length; i++)
            {
                int j = RandomNumbers.Next(0, 3);

                switch (j)
                {
                    case 0:
                        result += (char)RandomNumbers.Next(48, 58);
                        break;
                    case 1:
                        result += (char)RandomNumbers.Next(65, 91);
                        break;
                    case 2:
                        result += (char)RandomNumbers.Next(97, 123);
                        break;
                }
                //char c = (char)32;

                //create a new line with a probability of 0.01 (1%)
                int newLine = RandomNumbers.Next(0, 100);
                if (newLine == 15)
                    result += "\n";
            }

            //65-91: A-Z
            //97-123: a-z

            return result;
        }

        public static TextElementAnimationMode GetRandomTextElementMode(bool onlyReadingDirection = false)
        {
            TextElementAnimationMode mode = TextElementAnimationMode.LeftToRight;

            int i = RandomNumbers.Next(0, 4);

            switch (i)
            {
                case 0:
                    mode = !onlyReadingDirection ? TextElementAnimationMode.LeftToRight : TextElementAnimationMode.RightToLeft;
                    break;
                case 1:
                    mode = TextElementAnimationMode.RightToLeft;
                    break;
                case 2:
                    mode = !onlyReadingDirection ? TextElementAnimationMode.TopDown : TextElementAnimationMode.BottomUp;
                    break;
                case 3:
                    mode = TextElementAnimationMode.BottomUp;
                    break;
            }

            return mode;
        }

        internal static string ConvertTextToVertical(string text)
        {
            string result = text;

            for (int i = 1; i < (text.Length - 1) * 3; i += 3)
            {
                result = result.Insert(i, Environment.NewLine);
            }

            return result;
        }

        internal static string AddSpacesToText(string text, int count)
        {
            string spaces = String.Empty;


            for (int i = 0; i < count; i++)
            {
                spaces = spaces.Insert(0, " ");
            }

            string result = text;

            for (int i = 1; i < (text.Length - 1) * (spaces.Length + 1); i += (spaces.Length + 1))
            {
                result = result.Insert(i, spaces);
            }

            return result;
        }
    }
}
